﻿using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using T4.Console.Db.Models;

#nullable disable

namespace T4.Console.Db.Data
{
    public partial class ItechRunTestContext : DbContext
    {
        public ItechRunTestContext()
        {
        }

        public ItechRunTestContext(DbContextOptions<ItechRunTestContext> options)
            : base(options)
        {
        }

        public virtual DbSet<Blog_Collect> Blog_Collects { get; set; }
        public virtual DbSet<Blog_Comment> Blog_Comments { get; set; }
        public virtual DbSet<Blog_Focus> Blog_Foci { get; set; }
        public virtual DbSet<Blog_Info> Blog_Infos { get; set; }
        public virtual DbSet<Blog_Interest> Blog_Interests { get; set; }
        public virtual DbSet<Blog_PersonCategory> Blog_PersonCategories { get; set; }
        public virtual DbSet<Blog_PersonCategory_Map> Blog_PersonCategory_Maps { get; set; }
        public virtual DbSet<Blog_PersonLabel> Blog_PersonLabels { get; set; }
        public virtual DbSet<Blog_PersonLabel_Map> Blog_PersonLabel_Maps { get; set; }
        public virtual DbSet<Blog_Personal> Blog_Personals { get; set; }
        public virtual DbSet<Sys_Button> Sys_Buttons { get; set; }
        public virtual DbSet<Sys_Dictionary> Sys_Dictionaries { get; set; }
        public virtual DbSet<Sys_Job> Sys_Jobs { get; set; }
        public virtual DbSet<Sys_Module> Sys_Modules { get; set; }
        public virtual DbSet<Sys_ModuleButton> Sys_ModuleButtons { get; set; }
        public virtual DbSet<Sys_ProcedureException> Sys_ProcedureExceptions { get; set; }
        public virtual DbSet<Sys_Role> Sys_Roles { get; set; }
        public virtual DbSet<Sys_RoleModule> Sys_RoleModules { get; set; }
        public virtual DbSet<Sys_RoleModuleButton> Sys_RoleModuleButtons { get; set; }
        public virtual DbSet<Sys_TokenGrey> Sys_TokenGreys { get; set; }
        public virtual DbSet<Sys_User> Sys_Users { get; set; }
        public virtual DbSet<Sys_UserRole> Sys_UserRoles { get; set; }
        public virtual DbSet<Sys_User_RefreshToken> Sys_User_RefreshTokens { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
                optionsBuilder.UseSqlServer("Server=.;Database=ItechRun-Test;Trusted_Connection=True;");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasAnnotation("Relational:Collation", "Chinese_PRC_CI_AS");

            modelBuilder.Entity<Blog_Collect>(entity =>
            {
                entity.Property(e => e.Id).IsUnicode(false);

                entity.Property(e => e.BlogId).IsUnicode(false);

                entity.Property(e => e.CollectId).IsUnicode(false);

                entity.Property(e => e.CreatedBy).IsUnicode(false);

                entity.Property(e => e.LastModifiedBy).IsUnicode(false);

                entity.HasOne(d => d.Blog)
                    .WithMany(p => p.Blog_Collects)
                    .HasForeignKey(d => d.BlogId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BLOG_COLLECT_REFERENCE_31_BLOG_INFO");

                entity.HasOne(d => d.Collect)
                    .WithMany(p => p.Blog_Collects)
                    .HasForeignKey(d => d.CollectId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BLOG_COLLECT_REFERENCE_7_SYS_USER");
            });

            modelBuilder.Entity<Blog_Comment>(entity =>
            {
                entity.Property(e => e.Id).IsUnicode(false);

                entity.Property(e => e.BlogId).IsUnicode(false);

                entity.Property(e => e.CreatedBy).IsUnicode(false);

                entity.Property(e => e.LastModifiedBy).IsUnicode(false);

                entity.Property(e => e.RelationCommentId).IsUnicode(false);

                entity.HasOne(d => d.Blog)
                    .WithMany(p => p.Blog_Comments)
                    .HasForeignKey(d => d.BlogId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BLOG_COMMENT_REFERENCE_32_BLOG_INFO");
            });

            modelBuilder.Entity<Blog_Focus>(entity =>
            {
                entity.Property(e => e.Id).IsUnicode(false);

                entity.Property(e => e.CreatedBy)
                    .IsUnicode(false)
                    .UseCollation("SQL_Latin1_General_CP1_CI_AS");

                entity.Property(e => e.FocusOnId).IsUnicode(false);

                entity.Property(e => e.LastModifiedBy)
                    .IsUnicode(false)
                    .UseCollation("SQL_Latin1_General_CP1_CI_AS");

                entity.Property(e => e.PersonId).IsUnicode(false);

                entity.HasOne(d => d.FocusOn)
                    .WithMany(p => p.Blog_FocusFocusOns)
                    .HasForeignKey(d => d.FocusOnId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BLOG_FOC_REFERENCE_SYS_USER_FocusOnId");

                entity.HasOne(d => d.Person)
                    .WithMany(p => p.Blog_FocusPeople)
                    .HasForeignKey(d => d.PersonId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BLOG_FOC_REFERENCE_SYS_USER_PersonId");
            });

            modelBuilder.Entity<Blog_Info>(entity =>
            {
                entity.Property(e => e.Id).IsUnicode(false);

                entity.Property(e => e.Author).IsUnicode(false);

                entity.Property(e => e.Category)
                    .HasDefaultValueSql("((1))")
                    .HasComment("1 随笔\r\n   2 文章\r\n   3 日记");

                entity.Property(e => e.CreatedBy).IsUnicode(false);

                entity.Property(e => e.IsTop).HasDefaultValueSql("((0))");

                entity.Property(e => e.LastModifiedBy).IsUnicode(false);

                entity.Property(e => e.WhoVisit).HasComment("1 公开\r\n   2 仅登录用户\r\n   3 只有我");

                entity.HasOne(d => d.AuthorNavigation)
                    .WithMany(p => p.Blog_Infos)
                    .HasForeignKey(d => d.Author)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BLOG_INFO_REFERENCE_25_SYS_USER");
            });

            modelBuilder.Entity<Blog_Interest>(entity =>
            {
                entity.Property(e => e.Id).IsUnicode(false);

                entity.Property(e => e.BlogId).IsUnicode(false);

                entity.Property(e => e.CreatedBy).IsUnicode(false);

                entity.Property(e => e.LastModifiedBy).IsUnicode(false);

                entity.HasOne(d => d.Blog)
                    .WithOne(p => p.Blog_Interest)
                    .HasForeignKey<Blog_Interest>(d => d.BlogId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BLOG_INTEREST_REFERENCE_30_BLOG_INFO");
            });

            modelBuilder.Entity<Blog_PersonCategory>(entity =>
            {
                entity.Property(e => e.Id).IsUnicode(false);

                entity.Property(e => e.CreatedBy).IsUnicode(false);

                entity.Property(e => e.LastModifiedBy).IsUnicode(false);

                entity.Property(e => e.UserId).IsUnicode(false);

                entity.HasOne(d => d.User)
                    .WithMany(p => p.Blog_PersonCategories)
                    .HasForeignKey(d => d.UserId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BLOG_PER_REFERENCE_SYS_USER14");
            });

            modelBuilder.Entity<Blog_PersonCategory_Map>(entity =>
            {
                entity.Property(e => e.Id).IsUnicode(false);

                entity.Property(e => e.BlogId).IsUnicode(false);

                entity.Property(e => e.CreatedBy).IsUnicode(false);

                entity.Property(e => e.LastModifiedBy).IsUnicode(false);

                entity.Property(e => e.PersonCategoryId).IsUnicode(false);

                entity.HasOne(d => d.Blog)
                    .WithMany(p => p.Blog_PersonCategory_Maps)
                    .HasForeignKey(d => d.BlogId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BLOG_PERSONCATEGORY_MAP_REFERENCE_28_BLOG_INFO");

                entity.HasOne(d => d.PersonCategory)
                    .WithMany(p => p.Blog_PersonCategory_Maps)
                    .HasForeignKey(d => d.PersonCategoryId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BLOG_PERSONCATEGORY_MAP_REFERENCE_27_BLOG_PERSONCATEGORY");
            });

            modelBuilder.Entity<Blog_PersonLabel>(entity =>
            {
                entity.Property(e => e.Id).IsUnicode(false);

                entity.Property(e => e.CreatedBy).IsUnicode(false);

                entity.Property(e => e.LastModifiedBy).IsUnicode(false);

                entity.Property(e => e.UserId).IsUnicode(false);

                entity.HasOne(d => d.User)
                    .WithMany(p => p.Blog_PersonLabels)
                    .HasForeignKey(d => d.UserId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BLOG_PERSONLABEL_REFERENCE_10_SYS_USER");
            });

            modelBuilder.Entity<Blog_PersonLabel_Map>(entity =>
            {
                entity.Property(e => e.Id).IsUnicode(false);

                entity.Property(e => e.BlogId).IsUnicode(false);

                entity.Property(e => e.CreatedBy).IsUnicode(false);

                entity.Property(e => e.LastModifiedBy).IsUnicode(false);

                entity.Property(e => e.PersonLabelId).IsUnicode(false);

                entity.HasOne(d => d.Blog)
                    .WithMany(p => p.Blog_PersonLabel_Maps)
                    .HasForeignKey(d => d.BlogId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BLOG_PERSONLABEL_MAP_REFERENCE_29_BLOG_INFO");

                entity.HasOne(d => d.PersonLabel)
                    .WithMany(p => p.Blog_PersonLabel_Maps)
                    .HasForeignKey(d => d.PersonLabelId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BLOG_PER_REFERENCE_BLOG_PER7");
            });

            modelBuilder.Entity<Blog_Personal>(entity =>
            {
                entity.Property(e => e.Id).IsUnicode(false);

                entity.Property(e => e.CreatedBy)
                    .IsUnicode(false)
                    .UseCollation("SQL_Latin1_General_CP1_CI_AS");

                entity.Property(e => e.LastModifiedBy)
                    .IsUnicode(false)
                    .UseCollation("SQL_Latin1_General_CP1_CI_AS");

                entity.Property(e => e.MarriageStatus).HasComment("单身\r\n   热恋中\r\n   订婚\r\n   已婚\r\n   离异");

                entity.Property(e => e.UserId).IsUnicode(false);

                entity.Property(e => e.WorkingStatus).HasComment("学生\r\n   已工作\r\n   待业中\r\n   其它");

                entity.HasOne(d => d.User)
                    .WithOne(p => p.Blog_Personal)
                    .HasForeignKey<Blog_Personal>(d => d.UserId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_BLOG_PER_REFERENCE_SYS_USER12");
            });

            modelBuilder.Entity<Sys_Button>(entity =>
            {
                entity.Property(e => e.Id).IsUnicode(false);

                entity.Property(e => e.Code).IsUnicode(false);

                entity.Property(e => e.CreatedBy).IsUnicode(false);

                entity.Property(e => e.LastModifiedBy).IsUnicode(false);

                entity.Property(e => e.Sort).HasDefaultValueSql("((1000))");
            });

            modelBuilder.Entity<Sys_Dictionary>(entity =>
            {
                entity.Property(e => e.Id).IsUnicode(false);

                entity.Property(e => e.Category).HasComment("1 普通\r\n   2 附件");

                entity.Property(e => e.CodeType).HasComment("1 字典类别：Code、Name分别对应类别编码及名称【预定义好】；预定义好的对应如下；\r\n   2 多语言\r\n   3 注册类型(供应商属性)\r\n   4 国家/地区\r\n   5 通信语言\r\n   6 管理人员职务(SPOC-职位)\r\n   7 国际地址版本\r\n   8 业务类型(暂仅BPM创建邀请链接用到)【暂不维护 - 仅预留】\r\n   9 账户组(暂仅BPM创建邀请链接用到)【暂不维护 - 仅预留】\r\n   10 TPV合规审查状态\r\n   11 操作手册\r\n   12 品类选择指引\r\n   13 ABI所在国家（包括问卷、国家地址版本的国家等）\r\n   14 开户行默认申请人\r\n   15 企业所有制\r\n   16 代理收款人类型\r\n   17 供应商校验基本信息Code\r\n   18 供应商类型\r\n   19 设施（分公司）类型\r\n   20 企业信息验证的有效天数\r\n   21公邮\r\n   \r\n   \r\n   \r\n   \r\n   ");

                entity.Property(e => e.CreatedBy).IsUnicode(false);

                entity.Property(e => e.LastModifiedBy).IsUnicode(false);
            });

            modelBuilder.Entity<Sys_Job>(entity =>
            {
                entity.Property(e => e.Id).IsUnicode(false);

                entity.Property(e => e.CreatedBy).IsUnicode(false);

                entity.Property(e => e.CronExpression).IsUnicode(false);

                entity.Property(e => e.LastModifiedBy).IsUnicode(false);
            });

            modelBuilder.Entity<Sys_Module>(entity =>
            {
                entity.Property(e => e.Id).IsUnicode(false);

                entity.Property(e => e.ApiController).IsUnicode(false);

                entity.Property(e => e.ApplicationCode).HasComment("Back");

                entity.Property(e => e.CreatedBy).IsUnicode(false);

                entity.Property(e => e.LastModifiedBy).IsUnicode(false);

                entity.Property(e => e.ParentId).IsUnicode(false);
            });

            modelBuilder.Entity<Sys_ModuleButton>(entity =>
            {
                entity.Property(e => e.Id).IsUnicode(false);

                entity.Property(e => e.ButtonId).IsUnicode(false);

                entity.Property(e => e.CreatedBy).IsUnicode(false);

                entity.Property(e => e.LastModifiedBy).IsUnicode(false);

                entity.Property(e => e.ModuleId).IsUnicode(false);

                entity.HasOne(d => d.Button)
                    .WithMany(p => p.Sys_ModuleButtons)
                    .HasForeignKey(d => d.ButtonId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_SYS_MODU_REFERENCE_SYS_BUTT6");

                entity.HasOne(d => d.Module)
                    .WithMany(p => p.Sys_ModuleButtons)
                    .HasForeignKey(d => d.ModuleId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_SYS_MODU_REFERENCE_SYS_MODU5");
            });

            modelBuilder.Entity<Sys_ProcedureException>(entity =>
            {
                entity.Property(e => e.Id).IsUnicode(false);

                entity.Property(e => e.CreatedBy).IsUnicode(false);

                entity.Property(e => e.LastModifiedBy).IsUnicode(false);
            });

            modelBuilder.Entity<Sys_Role>(entity =>
            {
                entity.Property(e => e.Id).IsUnicode(false);

                entity.Property(e => e.CreatedBy).IsUnicode(false);

                entity.Property(e => e.LastModifiedBy).IsUnicode(false);
            });

            modelBuilder.Entity<Sys_RoleModule>(entity =>
            {
                entity.Property(e => e.Id).IsUnicode(false);

                entity.Property(e => e.CreatedBy).IsUnicode(false);

                entity.Property(e => e.LastModifiedBy).IsUnicode(false);

                entity.Property(e => e.ModuleId).IsUnicode(false);

                entity.Property(e => e.RoleId).IsUnicode(false);

                entity.HasOne(d => d.Module)
                    .WithMany(p => p.Sys_RoleModules)
                    .HasForeignKey(d => d.ModuleId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_SYS_ROLE_REFERENCE_SYS_MODU7");

                entity.HasOne(d => d.Role)
                    .WithMany(p => p.Sys_RoleModules)
                    .HasForeignKey(d => d.RoleId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_SYS_ROLE_REFERENCE_SYS_ROLE4");
            });

            modelBuilder.Entity<Sys_RoleModuleButton>(entity =>
            {
                entity.Property(e => e.Id).IsUnicode(false);

                entity.Property(e => e.ButtonId).IsUnicode(false);

                entity.Property(e => e.CreatedBy).IsUnicode(false);

                entity.Property(e => e.LastModifiedBy).IsUnicode(false);

                entity.Property(e => e.ModuleId).IsUnicode(false);

                entity.Property(e => e.RoleId).IsUnicode(false);

                entity.HasOne(d => d.Button)
                    .WithMany(p => p.Sys_RoleModuleButtons)
                    .HasForeignKey(d => d.ButtonId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_SYS_ROLE_REFERENCE_SYS_BUTT10");

                entity.HasOne(d => d.Module)
                    .WithMany(p => p.Sys_RoleModuleButtons)
                    .HasForeignKey(d => d.ModuleId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_SYS_ROLE_REFERENCE_SYS_MODU9");

                entity.HasOne(d => d.Role)
                    .WithMany(p => p.Sys_RoleModuleButtons)
                    .HasForeignKey(d => d.RoleId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_SYS_ROLE_REFERENCE_SYS_ROLE8");
            });

            modelBuilder.Entity<Sys_TokenGrey>(entity =>
            {
                entity.Property(e => e.Id).IsUnicode(false);

                entity.Property(e => e.CreatedBy).IsUnicode(false);

                entity.Property(e => e.LastModifiedBy).IsUnicode(false);

                entity.Property(e => e.Token).IsUnicode(false);
            });

            modelBuilder.Entity<Sys_User>(entity =>
            {
                entity.Property(e => e.Id).IsUnicode(false);

                entity.Property(e => e.Category).HasComment("1 博客");

                entity.Property(e => e.CreatedBy).IsUnicode(false);

                entity.Property(e => e.LastModifiedBy).IsUnicode(false);

                entity.Property(e => e.Sex).HasComment("1 男\r\n   2 女");

                entity.Property(e => e.Sort).HasDefaultValueSql("((1000))");
            });

            modelBuilder.Entity<Sys_UserRole>(entity =>
            {
                entity.Property(e => e.Id).IsUnicode(false);

                entity.Property(e => e.CreatedBy).IsUnicode(false);

                entity.Property(e => e.LastModifiedBy).IsUnicode(false);

                entity.Property(e => e.RoleId).IsUnicode(false);

                entity.Property(e => e.UserId).IsUnicode(false);

                entity.HasOne(d => d.Role)
                    .WithMany(p => p.Sys_UserRoles)
                    .HasForeignKey(d => d.RoleId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_SYS_USER_REFERENCE_SYS_ROLE3");

                entity.HasOne(d => d.User)
                    .WithMany(p => p.Sys_UserRoles)
                    .HasForeignKey(d => d.UserId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_SYS_USER_REFERENCE_SYS_USER2");
            });

            modelBuilder.Entity<Sys_User_RefreshToken>(entity =>
            {
                entity.Property(e => e.Id).IsUnicode(false);

                entity.Property(e => e.CreatedBy).IsUnicode(false);

                entity.Property(e => e.LastModifiedBy).IsUnicode(false);

                entity.Property(e => e.Token).IsUnicode(false);

                entity.Property(e => e.UserId).IsUnicode(false);

                entity.HasOne(d => d.User)
                    .WithMany(p => p.Sys_User_RefreshTokens)
                    .HasForeignKey(d => d.UserId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_SYS_USER_REFERENCE_SYS_USER1");
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
